package io.cloud.tec.project.component;

import io.cloud.tec.project.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 启动参数
 * @author Administrator
 */
@Slf4j
@Component
public class ApplicationArgumentsRunner implements ApplicationRunner {

    final ApplicationArguments applicationArguments;

    public ApplicationArgumentsRunner(ApplicationArguments applicationArguments) {
        this.applicationArguments = applicationArguments;
    }

    @Override
    public void run(ApplicationArguments args) {
        Set<String> optionNames = applicationArguments.getOptionNames();
        log.info(">>>>>>>>OptionNames>>>>>>>>");
        optionNames.forEach(on -> log.info("{}-{}", on, applicationArguments.getOptionValues(on)));
        log.info("<<<<<<<<OptionNames<<<<<<<<<");
        log.info("NonOptionArgs: {}", JsonUtils.toJsonString(applicationArguments.getNonOptionArgs()));
    }
}
